/*
 * @lc app=leetcode.cn id=205 lang=csharp
 *
 * [205] 同构字符串
 */

// @lc code=start
public class Solution {
    public bool IsIsomorphic(string s, string t) {
        Dictionary<char, char> dict = new Dictionary<char, char>();
        Dictionary<char, char> dict2 = new Dictionary<char, char>();
        for( int i = 0; i < s.Length; ++i)
        {
            var cs = s[i];
            var ct = t[i];
            char mapTChar;
            if(!dict.TryGetValue(cs, out mapTChar))
            {
                if(dict2.TryGetValue(ct, out char c))
                    return false;
                
                dict.Add(cs, ct);
                dict2.Add(ct, cs);
            }
            else if(mapTChar != ct)
                return false;
        }
        return true;
    }
}
// @lc code=end

